package com.panlf.springbootdemo.service;

import com.panlf.springbootdemo.dao.UserDao;
import com.panlf.springbootdemo.entity.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author panlf
 * @since 2024/1/26 14:13
 */
@Service
public class UserService {

    @Resource
    private UserDao userDao;

    @Transactional(rollbackFor = Exception.class)
    public void addAndException(UserEntity user) {
        userDao.insert(user);
        throw new RuntimeException("service 手动异常");
    }

    @Transactional(rollbackFor = Exception.class)
    public void add(UserEntity user) {
        userDao.insert(user);
    }
}
